package 学生评教管理系统;

import java.util.ArrayList;
import java.util.Scanner;

public class Operator {
    Scanner scan;

    Operator() {
        scan = new Scanner(System.in);
    }


    //查询学生所有信息
    public static void showAllStudent(ArrayList<Student> list) {

        //思路：	遍历集合，获得每一个学生对象，再输出学生对象的信息
        System.out.println("学号\t\t\t姓名\t\t\t年龄\t\t住址");
        for (Student stu : list) {
            System.out.println(stu.getSid() + "\t\t" + stu.getName() + "\t\t" + stu.getAge() + "\t\t" + stu.getAddress());
        }
    }

    //添加学生
    public static void addStudents(ArrayList<Student> list) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入学号：");
        int sid = sc.nextInt();

        System.out.println("请输入姓名：");
        String name = sc.next();

        System.out.println("请输入年龄：");
        int age = sc.nextInt();

        System.out.println("请输入住址：");
        String address = sc.next();

        //2.	将学生的信息包装到Student Bean中
        Student stu = new Student(sid, name, age, address);

        //3.	将学生这个对象保存到集合中
        list.add(stu);

        System.out.println("添加成功！");
    }

    //修改学生
    public static void reviseStudent(ArrayList<Student> list) {
        // TODO Auto-generated method stub

        //1.	判断集合中有没有学生信息
        Scanner sc = new Scanner(System.in);

        if (list.size() == 0) {
            System.out.println("当前没有学生信息");
            return;  //return直接跳出当前语句，不会执行下面的语句
        }

        //2.	输入要修改的学生学号
        System.out.println("请输入您想修改的学生学号：");
        int id = sc.nextInt();

        //3.	判断输入的id是否在list集合中，如果在，则执行一系列的代码，如果不在，直接跳出
        boolean flag = false;

        for (int i = 0; i < list.size(); i++) {

            if (list.get(i).getSid() == id) {
                flag = true;

                //4.	提示用户输入新的学生信息(学号、姓名、年龄、住址)
                System.out.println("请输入新的学号：");
                int sidNew = sc.nextInt();

                System.out.println("请输入新的姓名：");
                String nameNew = sc.next();

                System.out.println("请输入新的年龄：");
                int ageNew = sc.nextInt();

                System.out.println("请输入新的住址：");
                String addressNew = sc.next();

                //5.	将接受到的学生的信息重新包装到Student Bean中
                Student stu = new Student(sidNew, nameNew, ageNew, addressNew);

                //6.	将集合进行修改
                list.set(i, stu);

                System.out.println("修改成功！");
                break;

            }
        }
        if (flag == false) {
            System.out.println("没有找到该学生，请重新输入:");
        }

    }


    //删除学生
    public static void delStudent(ArrayList<Student> list) {

        //1.	判断集合中有没有学生信息
        Scanner sc = new Scanner(System.in);

        if (list.size() == 0) {
            System.out.println("当前没有学生信息");
            return;  //return直接跳出当前语句，不会执行下面的语句
        }

        //2.	输入要删除的学生的学号
        System.out.println("请输入您想要删除的学生学号：");
        int id = sc.nextInt();

        //3.	判断输入的id是否在list集合中，如果在，则执行一系列的代码，如果不在，直接跳出

        boolean flag = false;

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getSid() == id) {
                flag = true;

                list.remove(i);
                System.out.println("删除成功！");
                return;  //break结束当前语句，下面的代码会继续执行
            }
        }
        if (flag == false) {
            System.out.println("未找到您想要删除的学生信息，请重新输入");
        }
    }

    //录入课程
    public void addCourses(Course[] courses) {
        System.out.println("请输入学生信息：格式为课程号,课程名,学分");
        String str;
        String sInfor[];
        for (int i = 0; i < courses.length; i++) {
            str = scan.next();
            sInfor = str.split(",");
            courses[i] = new Course(sInfor[0], sInfor[1], Double.parseDouble(sInfor[2]));
        }
    }

    //显示所有课程
    public void displayCourses(Course[] courses) {
        for (int i = 0; i < courses.length; i++) {
            System.out.println("课程号：" + courses[i].getCourseId() + ",课程名：" + courses[i].getCourseName()
                    + ",学分：" + courses[i].getCredit());
        }
    }

    //删除某门课程
    public void delCourses(Course[] courses) {
        System.out.println("请输入要删除课程的编号：");
        String courseId = scan.next();
        for (int i = 0; i < courses.length; i++) {
            if (courses[i].getCourseId().equals(courseId)) {
                courses[i] = null;
                System.out.println("删除成功！");
            }
        }
    }


    //录入教师
    public void addTeachers(Teacher[] teachers) {
        System.out.println("请输入教师信息：格式为工号,姓名,性别,电话,职称,年龄");
        String str;
        String sInfor[];
        for (int i = 0; i < teachers.length; i++) {
            str = scan.next();
            sInfor = str.split(",");
            teachers[i] = new Teacher(sInfor[0], sInfor[1], sInfor[2], sInfor[3], sInfor[4], Integer.parseInt(sInfor[5]));
        }
    }

    //   显示教师所有信息
    public void displayTeachers(Teacher[] teachers) {
        for (int i = 0; i < teachers.length; i++) {
            System.out.println("工号：" + teachers[i].getTeaId() + ",姓名：" + teachers[i].getTeaName()
                    + ",性别：" + teachers[i].getSex() + ",电话：" + teachers[i].getTel()
                    + ",职称：" + teachers[i].getProfessor() + ",年龄：" + teachers[i].getAge());
            //if(teachers[i].teachCourse!=null){
            //    for(int j=0;j<teachers[i].teachCourse.length;j++){
            //        System.out.println("\t\t课程编号："+teachers[i].teachCourse[j].courseId+",授课评价："+teachers[i].teachCourse[j].evaluate);
            //    }
            //}
        }
    }

    //教师排课
    public void assignTeachCourses(Teacher[] teachers, Course[] courses) {
        System.out.println();
        System.out.println("\t课程信息系如下：");
        for (int i = 0; i < courses.length; i++) {
            System.out.println("课程号：" + courses[i].getCourseId()
                    + "\t" + "课程名称：" + courses[i].getCourseName());
        }
        System.out.println();
        System.out.println("请选择课程，格式为：课程号1,课程号2,......");
        for (int i = 0; i < teachers.length; i++) {
            System.out.println("工号：" + teachers[i].getTeaId()
                    + "，姓名：" + teachers[i].getTeaName() + " 排课(请输入课程号)：");
            String[] cIds = scan.next().split(",");
            teachers[i].setTeachCourse(cIds);

        }
    }

    //查询教师与课程号的对应信息
    public void showCourses(Teacher[] teachers, Course[] courses) {

        System.out.println("教师与课程号的对应关系如下：");
        for (int i = 0; i < teachers.length; i++) {
            if (teachers[i].teachCourse.length > 0) {
                for (int j = 0; j < teachers[i].teachCourse.length; j++) {
                    System.out.println("课程号：" + teachers[i].teachCourse[j]
                            + "\t" + "课程名称：" + courses[Integer.parseInt(teachers[i].teachCourse[j]) - 1].getCourseName() + "\t教师工号：" + teachers[i].getTeaId() + "\t教师姓名：" + teachers[i].getTeaName());

                }
            }
        }


    }

    //学生登录
    public static boolean inputEvaluate(int studentId, int passworld, ArrayList<Student> list) {
        Scanner scans = new Scanner(System.in);
        boolean flag = false;

        for (int i = 0; i < list.size(); i++) {

            if (list.get(i).getSid() == studentId && passworld == 123456) {
                System.out.println("登录成功！");
                flag = true;
                break;
            } else {
                flag = false;
            }

        }

        return flag;
    }

    //授课评价
    public void evaluate(Teacher[] teachers) {
        Scanner input = new Scanner(System.in);
        for (int i = 0; i < teachers.length; i++) {
            System.out.println("请输入对第" + (i + 1) + "位老师的评价：");
            String pingjia = input.next();

            System.out.println("学生对第" + (i + 1) + "位老师的评价：" + pingjia);
        }

    }


}